using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zephyris_Space_Mercs
{
    class Ping
    {
        private static int testCount = 0;
        private static DateTime startTestDateTime;
        private static PeerNode peerNode;

        public static void StartPingTest(PeerNode PeerNode)
        {
            peerNode = PeerNode;
            LANMultiPlayerMenu.processString += "Pinging..." + System.Environment.NewLine;
            peerNode.Send("PING:");
            startTestDateTime = DateTime.Now;
        }

        public static void SetPingTest()
        {
            testCount++;
            if (testCount < Constants.maxTestCount)
            {
                peerNode.Send("PING:");
            }
            else
            {
                ResetPingTest();
            }
        }

        private static void ResetPingTest()
        {
            TimeSpan timeTaken = DateTime.Now - startTestDateTime;
            double milliseconds = timeTaken.TotalMilliseconds;

            double roundTrip = milliseconds / Constants.maxTestCount;

            LANMultiPlayerMenu.processString  += "Ping results...Round Trip " + Math.Round(roundTrip, 1).ToString() + "ms" + System.Environment.NewLine;
            testCount = 0;
        }
    }
}
